package com.moter.estest.config;

import com.moter.estest.util.ESProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {
    @Autowired
    private ESProperties esProperties;
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        String url[] = esProperties.getUrl().split(":");
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(url[0], Integer.parseInt(url[1].trim()), "http")
                ));
        return client;
    }
}
